package com.cuixk.basic.quartz.manager.util;

import com.cuixk.basic.quartz.manager.bean.QuartzJob;
import com.cuixk.basic.quartz.manager.bean.QuartzTrigger;
import com.cuixk.basic.quartz.manager.job.MyJob;
import org.quartz.*;

/**
 * Create By Cuixk
 * 2019/6/21 16:51
 */
public class ScheduleUtil {

    public static CronTrigger buildCronTrigger(QuartzTrigger trigger){
        return TriggerBuilder.newTrigger()
                .withIdentity(trigger.getTriggerName(), trigger.getTriggerGroup())
                .usingJobData(trigger.getTriggerKey(), trigger.getTriggerValue())
                .startAt(trigger.getStartAt())
                .withSchedule(CronScheduleBuilder.cronSchedule(trigger.getCronExpression()))
                .build();
    }

    public static JobDetail buildJonDetail(QuartzJob job){
        return JobBuilder.newJob(MyJob.class)
                .withIdentity(job.getJobName(), job.getJobGroup())
                .usingJobData(job.getJobKey(), job.getJobValue())
                .build();
    }
}
